package com.song.redis;

import redis.clients.jedis.Jedis;

import java.util.Random;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class MyRedisTest {

    private static final String watchkeys = "watchkeys";

    public static void main(String[] args) {
        final Jedis jedis = new Jedis("127.0.0.1", 6379);
        jedis.auth("redisroot");
        jedis.set(watchkeys, "10");
        jedis.close();
        ExecutorService executor = Executors.newFixedThreadPool(20);  //20个线程池并发数
        for (int i = 0; i < 100; i++) { //设置1000人来抢购
            executor.execute(new MyRunnable("user" + i));
        }

    }


    public static String getRandomString(int length) { //length是随机字符串长度
        String base = "abcdefghij";
        Random random = new Random();
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < length; i++) {
            int number = random.nextInt(base.length());
            sb.append(base.charAt(number));
        }
        return sb.toString();
    }


}
